package net.sycu.wj.ems.servlet.user;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sycu.wj.ems.business.UserService;
import net.sycu.wj.ems.entity.LoginBean;
import net.sycu.wj.ems.entity.UserBean;
import net.sycu.wj.ems.servlet.BaseServlet;

public class ModifyInformationServlet extends BaseServlet {
	UserService service = new UserService();
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		UserBean searcher = service.select(this.getLogin().getLoginId());
		request.setAttribute("user", searcher);
		request.getRequestDispatcher("./modifyInformation.jsp").forward(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		UserBean user = new UserBean();
		LoginBean login = new LoginBean();
		user.setLoginId(this.getLogin().getLoginId());
		user.setUserName(this.getParameter("txtUserName"));
		user.setGender(this.getParameter("txtGender"));
		user.setBirthday(this.getDateParameter("txtBirthday"));
		user.setCardId(this.getParameter("txtCardId"));
		user.setRemark(this.getParameter("txtRemark"));
		login.setNickname(this.getParameter("txtNickname"));
		login.setEmail(this.getParameter("txtEmail"));
		if(service.select(this.getLogin().getLoginId()) == null){
			service.add(user, login);
		}else{
			service.modify(user, login);
		}
		doGet(request, response);
	}

}
